package com.bangdream.michelia.view.adapter;


import android.widget.ImageView;

import com.bangdream.michelia.R;
import com.bangdream.michelia.entity.MyExamBean;
import com.bangdream.michelia.entity.exam.ExamBean;
import com.bangdream.michelia.utils.DateUtil;
import com.bangdream.michelia.utils.ImageLoadUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;


public class MyExamAdapter extends BaseQuickAdapter<ExamBean, BaseViewHolder> {
    private int type;


    public MyExamAdapter(int layoutResId, int type) {
        super(layoutResId);
        this.type=type;
    }

    @Override
    protected void convert(BaseViewHolder helper, ExamBean item) {
        ImageView imageView = helper.getView(R.id.iv_head);
        ImageLoadUtils.ImageLoad(mContext, item.getFaceUri(), imageView, R.mipmap.kaoshi);

        helper.setText(R.id.tvPeopleNumber, item.getIsUsed()+"");
        helper.setText(R.id.tv_title, item.getTitle()+"");

        helper.setText(R.id.tv_state, type == 1 ? "考试成绩: 合格" : "考试成绩: 不合格");

        helper.setText(R.id.tv_time,item.getStartDate()+"");

        if(type == 1 ){
            helper.setVisible(R.id.btn1, false);
        }else if(type ==2 && item.getCanDuplication().equals("0")){//0不允许重考
            helper.setVisible(R.id.btn1, false);
        }


        long nmEndDate = DateUtil.stringToDate(item.getEndDate(),  DateUtil.DatePattern.ALL_TIME).getTime();
        long nmTodayDate = DateUtil.stringToDate(DateUtil.getNowDate( DateUtil.DatePattern.ALL_TIME),  DateUtil.DatePattern.ALL_TIME).getTime();

        //已结束
        if(nmEndDate<nmTodayDate){
            helper.setVisible(R.id.btn1, false);
            helper.setVisible(R.id.tvState, true);
        }else{
            helper.setVisible(R.id.tvState, false);
        }


        helper.addOnClickListener(R.id.btn3);
        helper.addOnClickListener(R.id.btn1);
    }
}
